package com.weiyi.mashangzhu.Roomer.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.squareup.okhttp.Request;
import com.weiyi.mashangzhu.API.API;
import com.weiyi.mashangzhu.Base.BaseActivity;
import com.weiyi.mashangzhu.R;
import com.weiyi.mashangzhu.Roomer.Bean.OneActivityBean;
import com.weiyi.mashangzhu.Utils.LoadingDialog;
import com.weiyi.mashangzhu.Utils.SPUtils;
import com.weiyi.mashangzhu.Utils.T;
import com.weiyi.mashangzhu.Utils.UiUtil;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class OneActivityActivity extends BaseActivity {
    String id;
    @BindView(R.id.bg)
    ImageView bg;
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.content)
    TextView content;
    @BindView(R.id.back)
    ImageView back;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.item_theme_1);
        ButterKnife.bind(this);
        id = getIntent().getStringExtra("id");
        initView();
    }

    //获取一个activity的信息
    @Override
    public void initView() {
        back.setVisibility(View.VISIBLE);
        LoadingDialog.show(this);
        super.initView();
        OkHttpUtils.get().addParams("token", SPUtils.get(this, "token", "") + "").addParams("id", id).url(API.BaseApi_R + API.Main_ActivityDetails_Api).build().execute(new StringCallback() {
            @Override
            public void onError(Request request, Exception e) {
                LoadingDialog.dismiss(OneActivityActivity.this);
                T.showShort(OneActivityActivity.this, "网络连接失败，请检查一下网络设置");
            }

            @Override
            public void onResponse(String response) {
                LoadingDialog.dismiss(OneActivityActivity.this);
                OneActivityBean oneActivityBean = new Gson().fromJson(response, OneActivityBean.class);
                Glide.with(OneActivityActivity.this).load(API.BaseApi_url + oneActivityBean.getData().getAcPic()).error(R.mipmap.errer).into(bg);
                title.setText(oneActivityBean.getData().getAcTitle());
                content.setText(oneActivityBean.getData().getAcContent());
                id = oneActivityBean.getData().getId() + "";
            }
        });
    }

    @OnClick({R.id.back, R.id.look})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.look:
                Intent intent = new Intent(this, RecommendActivity.class);
                intent.putExtra("info","activity");
                intent.putExtra("id", id);
                startActivity(intent);
                break;
        }
    }
}
